package com.gohome.gohomechat.ui.activity;

import android.view.View;
import android.widget.EditText;

import com.gohome.gohomechat.R;
import com.gohome.gohomechat.presenter.LoginPresenter;
import com.gohome.gohomechat.presenter.presenterlistener.LoginPresenterInterface;
import com.gohome.gohomechat.ui.viewlistener.LoginViewInterface;
import com.gohome.gohomechat.utils.ToActivityUtil;
import com.gohome.gohomechat.utils.ToastUtil;

/**
 * Created by dllo on 16/2/29.
 */
public class LoginActivity extends BaseActivity implements LoginViewInterface, View.OnClickListener {
    private EditText login_et_userName, login_et_userPsw;
    private LoginPresenterInterface loginPresenterInterface;

    @Override
    protected int getLayout() {
        return R.layout.activity_login;
    }

    @Override
    protected void initPresenter() {
        loginPresenterInterface = new LoginPresenter(this);
    }

    @Override
    protected void initView() {
        login_et_userName = findView(R.id.login_et_userName);
        login_et_userPsw = findView(R.id.login_et_userPsw);
        findView(R.id.login_btn_login).setOnClickListener(this);
        findView(R.id.login_btn_register).setOnClickListener(this);
    }

    @Override
    protected void initData() {

    }

    @Override
    public void showDialog() {
        showProgressDialog();
    }

    @Override
    public void dismissDialog() {
        dismissProgressDialog();
    }

    @Override
    public String userName() {
        return login_et_userName.getText().toString().trim();
    }

    @Override
    public String userPsw() {
        return login_et_userPsw.getText().toString().trim();
    }

    @Override
    public void toLoginSuccess() {
        ToActivityUtil.startToActivity(this, MainActivity.class);
        finish();
    }

    @Override
    public void toLoginFailed() {
        ToastUtil.showToast("登录失败");
    }

    @Override
    public void toRegisterSuccess() {
        ToActivityUtil.startToActivity(this, RegisterActivity.class);

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.login_btn_login:
                loginPresenterInterface.login();
                break;
            case R.id.login_btn_register:
                loginPresenterInterface.toRegisterActivit();
                break;
        }
    }
}
